import React, { useEffect, useRef } from "react";

function useThrottle(callBack, belay) {
  const timer = useRef(null);
  useEffect(() => {
    return () => {
      if (timer.current) {
        clearInterval(timer.current);
      }
    };
  });
  return ()=>{
    timer.current = setInterval(()=>{
        return (...arg)=>{
            callBack(...arg)
        }
    },belay)
  }
}

export default useThrottle;
